package com.techsoul.module.system.controller;

import com.techsoul.common.core.pojo.Result;
import com.techsoul.module.system.pojo.param.LoginParam;
import com.techsoul.module.system.pojo.param.OAuthParam;
import com.techsoul.module.system.pojo.param.UserWeChatSaveParam;
import com.techsoul.module.system.service.IAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 认证授权
 *
 * @author liuen
 */
@RestController
public class AuthController {

    @Autowired
    private Result result;
    
    @Autowired
    private IAuthService authService;
    /**
     * 登录
     * @param loginParam
     * @return
     */
    @PostMapping("/login")
    public Result login(@Valid @RequestBody LoginParam loginParam) {
        return result.success(authService.login(loginParam));
    }
    /**
     * 登录
     * @param loginParam
     * @return
     */
    @PostMapping("/loginAfterReg")
    public Result loginAfterReg(@Valid @RequestBody LoginParam loginParam) {
        return result.success(authService.loginAfterReg(loginParam));
    }

    /**
     * 微信登录
     * @param params
     * @return
     */
    @PostMapping("/wxAppletLogin")
    public Result wxAppletLogin(@Valid @RequestBody UserWeChatSaveParam params) {
        return result.success(authService.wxAppletLogin(params));
    }

    /**
     * 获取AccessToken
     * @param params
     * @return
     */
    @PostMapping("/api/getAccessToken")
    public Result getAccessToken(@Valid @RequestBody OAuthParam params) {
        return result.success(authService.getAccessToken(params));
    }

    /**
     * 获取登录用户信息
     * @return
     */
    @GetMapping("/getLoginUser")
    public Result getLoginUser() {
        return result.success(authService.getLoginUser());
    }

    /**
     * 获取登录用户的动态路由信息
     * @return
     */
    @GetMapping("/getRouters")
    public Result getRouters() {
        return result.success(authService.getRouters());
    }

}
